Interfaces are another type of facility in contracts to promote
abstraction. In interface, we can only define the functions and not
implement them. Also, all the functions have to be marked as
“external”. Apart from functions, interfaces can also declare enums,
structs, and events. Refer to the following code:
// SPDX-License-Identifier: SOME IDENTIFIER
pragma solidity ^0.8.10;
interface SomeInterface {
function someFunction() external pure returns(string
memory);
}
However, just like the abstract contract, an interface can’t be
deployed and would receive the following error:
“This contract may be abstract, and does not implement an abstract
parent’s functions completely or invoke an inherited contract’s
constructor correctly.”
Now, if we implement the following interface, we can find that it’s
working:
// SPDX-License-Identifier: SOME IDENTIFIER
pragma solidity ^0.8.10;
interface SomeInterface {
function someFunction() external pure returns(string
memory);
}
contract ImplementorContract is SomeInterface {
function someFunction() public override pure returns(string
memory) {
return “some message”;
}
}
In Solidity, we can also implement multiple interfaces at one time, as
shown as follows: